package com.lulu.baselib.dialog;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.lulu.baselib.R;

import butterknife.ButterKnife;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Author: XuChang
 * Date: 2019/10/26 14:01
 * Email: 123286473@qq.com
 * Description:bottomFragment基类
 * History:
 */
public abstract class BaseBottomFragment extends BottomSheetDialogFragment {

    CompositeDisposable compositeDisposable;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme);
    }

    protected void addDisposable(Disposable d){
        if(compositeDisposable==null){
            compositeDisposable = new CompositeDisposable();
        }
        compositeDisposable.add(d);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(compositeDisposable!=null){
            compositeDisposable.dispose();
            compositeDisposable.clear();
        }
    }

    protected abstract @LayoutRes
    int getLayoutId();

    protected abstract void initView(View view);

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(getLayoutId(), container);
        ButterKnife.bind(this, inflate);
        initView(inflate);
        return inflate;
    }
}
